﻿using UnityEngine;
using System.Collections;
using System; 

public class PickingUp : MonoBehaviour {

	public static int count = 0;
	public AudioClip[] Audio;
	public float _damage = 0.1f;
	public static int score=0;

	public class Manager{ 
		public static int deleteNum = 1; 
	} 



	void OnCollisionEnter2D(Collision2D collider)
	{
		if (gameObject.name.Contains("(Clone)"))
		{
			AudioSource.PlayClipAtPoint(Audio[0], transform.position);
		}
		else
		{
			DamagingCollider DamagingCollider = gameObject.GetComponent<DamagingCollider>();

			if(DamagingCollider){
				AudioSource.PlayClipAtPoint(Audio[0], transform.position);
				Destroy(gameObject);

			}
			else{
				AudioSource.PlayClipAtPoint(Audio[0], transform.position);
				


				Destroyable destroyable = collider.gameObject.GetComponent<Destroyable>();
				if(tag != Manager.deleteNum.ToString()){
					
					destroyable.Damage(_damage);
					int intVal = Convert.ToInt32(tag); 

					if(intVal>10){
						Destroy(gameObject);

					}
				}
				
				if(!DamagingCollider && tag == Manager.deleteNum.ToString()){
					score +=20;
					if(score>=100){
						Application.LoadLevel("CompleteScene");
					}
					Manager.deleteNum++; 
					print (Manager.deleteNum);
					GameObject.Instantiate(gameObject,new Vector3(4+count,4,0),Quaternion.identity);
					count ++;
					Destroy(gameObject);

				}	


			}

			
	
		




			//print ("current score = " + score);
		}	
	
	}	

	void OnGUI(){

		var myStyl = new GUIStyle();
		myStyl.normal.textColor = GUI.skin.label.normal.textColor;
		myStyl.fontSize = 80;

		GUI.Label(new Rect (40, 560, 100, 20), "Score = " + score, myStyl);

	}
}


